import 'dart:math';

import 'package:flutter/material.dart';
import 'package:order/generated/assets.dart';
import 'package:order/pages/home.dart';
import 'package:wave/config.dart';
import 'package:wave/wave.dart';

class Welcome extends StatefulWidget {
  const Welcome({super.key});

  @override
  State<Welcome> createState() => _WelcomeState();
}

class _WelcomeState extends State<Welcome> {


  @override
  Widget build(BuildContext context) {
    double screenWidth = MediaQuery
        .of(context)
        .size
        .width;

    return Scaffold(
        body: Stack(
          children: [
            Image.asset(
              Assets.imagesIconWelcome,
              height: double.infinity,
              width: double.infinity,
              fit: BoxFit.fill,
            ),
            SizedBox(
              height: double.infinity,
              child: Positioned(
                bottom: 0,
                child: WaveWidget(
                  config: CustomConfig(
                    colors: [
                      Colors.green[400]!,
                      Colors.indigo[300]!,
                      Colors.green[200]!,
                      Colors.green
                    ],
                    durations: [18000, 8000, 5000, 12000],
                    heightPercentages: [0.65, 0.9, 0.68, 3],
                  ),
                  size: const Size(double.infinity, double.infinity),
                  waveAmplitude: 0,
                ),
              ),
            ),
            Padding(
              padding: const EdgeInsets.only(top: 30, left: 50),
              child: Image.asset(
                Assets.imagesIconCompany,
                height: 80,
                fit: BoxFit.fitHeight,
              ),
            ),
            Positioned(bottom: 25, child: SizedBox(
              width: screenWidth,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  ElevatedButton(
                    style: ElevatedButton.styleFrom(
                      padding: const EdgeInsets.all(15),
                      backgroundColor: const Color(0xFFffca56)
                    ),
                    onPressed: () {
                      Navigator.of(context).pushAndRemoveUntil(
                          MaterialPageRoute(
                              builder: (context) => const Home()), (
                          route) => false);
                    },
                    child: SizedBox(
                      height: 90,
                      width: 150,
                      child: Column(
                          children: [
                            Image.asset(Assets.imagesIconOrders, height: 60,
                              fit: BoxFit.fitHeight,),
                            const Text("订单管理",
                              style: TextStyle(fontSize: 16, color: Colors.black),)
                          ],
                    )
                    ),
                  ),
                  const SizedBox(width: 50,),
                  InkWell(
                    onTap: () {},
                    child: Column(
                      children: [
                        Image.asset(Assets.imagesIconManager, height: 60,
                          fit: BoxFit.fitHeight,),
                        const Text("订单管理",
                          style: TextStyle(fontSize: 16, color: Colors.black),)
                      ],
                    ),
                  ),
                  const SizedBox(width: 80,)

                ],
              ),
            ),)
          ],
        ));
  }
}

class CurvedBackgroundPainter extends CustomPainter {
  final Paint _paint = Paint()
    ..color = Colors.blue;
  double _waveHeight = 0.0;
  double _waveWidth = 0.0;

  @override
  void paint(Canvas canvas, Size size) {
    _waveHeight = size.height * 0.15;
    _waveWidth = size.width * 0.9;

    var path = Path();
    path.moveTo(0, size.height - _waveHeight);

    for (var x = 0.0; x < size.width * 1.5; x += _waveWidth) {
      var y = size.height -
          _waveHeight * 2.0 * (1 + sin((x + 2 * pi * 2) / (_waveWidth * 4)));
      path.lineTo(x, y);
    }

    path.lineTo(size.width, size.height);
    path.lineTo(0, size.height);
    path.close();

    canvas.drawPath(path, _paint);
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }
}
